package ink.feta.task.job.registry;

import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobScheduler;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class JobRepository {

    private final Map<String, JobScheduler> schedulerMap = new ConcurrentHashMap<>();
    private static volatile JobRepository instance;

    public static JobRepository getInstance() {
        if (null == instance) {
            synchronized (JobRepository.class) {
                if (null == instance) {
                    instance = new JobRepository();
                }
            }
        }
        return instance;
    }

    public void save(String jobName, JobScheduler jobScheduler) {
        schedulerMap.put(jobName, jobScheduler);
    }

    public JobScheduler getJobScheduler(String jobName) {
        return schedulerMap.get(jobName);
    }
}
